<?php
//require_once 'Zend/View/Helper/Abstract.php';
class Zend_View_Helper_Qurl extends Zend_View_Helper_Abstract
{
    public function qurl (array $true_params)
    {
        $valid_params = array('order', 'order_field', 'q_id');
        $requestUri = \Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();
        $query = parse_url($requestUri, PHP_URL_QUERY);
        $path = parse_url($requestUri, PHP_URL_PATH);

        $params = urldecode($query);
        parse_str($params, $params);

        $navigation_params = array();

        foreach ($params as $key=>$item){
            if(in_array($key,$valid_params)){
                $navigation_params[$key]=$item;
            }
        }

        foreach($true_params as $key=>$item){
            $navigation_params[$key]=$item;
        }

        if(strpos($path, 'catalog')){
            $path='/search';
        }
//        die;
        $result_url = http_build_query($navigation_params);
        return trim($path.'?'.$result_url);
    }
}
